package com.yjhealth.libs.core.business.web;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.yjhealth.libs.core.R;
import com.yjhealth.libs.core.business.config.ThemeConfig;
import com.yjhealth.libs.core.core.activity.CoreWebActivity;
import com.yjhealth.libs.core.view.titlebar.BsoftToolbar;
import com.yjhealth.libs.core.view.titlebar.config.TitleButtonConfig;


public class SimpleWebActivity extends CoreWebActivity {
    /*Default*/
    public static final String INTENT_THEME = "theme_config";
    /*Util*/
    /*Flag*/
    private String url;
    private String title;
    private ThemeConfig themeConfig;
    /*View*/

    public static void appStart(Context context, String url, String title) {
        Intent web = new Intent(context, SimpleWebActivity.class);
        web.putExtra("url", url);
        web.putExtra("title", title);
        context.startActivity(web);
    }

    public static void appStart(Context context, String url, String title, ThemeConfig config) {
        Intent web = new Intent(context, SimpleWebActivity.class);
        web.putExtra("url", url);
        web.putExtra("title", title);
        web.putExtra(INTENT_THEME, config);
        context.startActivity(web);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.yjhealth_core_activity_simple_web);

        url = getIntent().getStringExtra("url");
        title = getIntent().getStringExtra("title");
        themeConfig = (ThemeConfig) getIntent().getSerializableExtra(INTENT_THEME);

        initLayout();

        load(url);
    }

    @Override
    protected void initLayout() {
        super.initLayout();
        initStatusBar();
    }

    @Override
    protected void setStatusBar() {
        yjhealthCoreBosftToolbar.setStatusBar();
    }

    private void initStatusBar() {
        yjhealthCoreBosftToolbar.setLisntener(new BsoftToolbar.OnBsoftToolbarLisntener() {
            @Override
            public void onItemClick(TitleButtonConfig config) {

            }

            @Override
            public void onBack() {
                onBackPressed();
            }

            @Override
            public void updateStatusBar() {
                setStatusBar();
            }
        });
        if (themeConfig != null && themeConfig.config != null) {
            themeConfig.config.title = title;
            yjhealthCoreBosftToolbar.setStatusTitle(themeConfig.config);
        } else {
            yjhealthCoreBosftToolbar.setTitle(title);
        }
    }
}
